package com.youtui.manager.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.youtui.common.util.DateTypeEditor;
import com.youtui.common.util.ExcelUtil;
import com.youtui.common.util.HttpClientUtil;
import com.youtui.common.util.JedisUtil;
import com.youtui.manager.session.SessionService;

/** baseController */
public class BaseController {

    protected final Logger logger = LoggerFactory.getLogger(getClass());
	/** 日志 */
	// protected @Autowired LoggerUtil loggerUtil;

	protected @Autowired HttpServletRequest request;

	protected @Autowired HttpServletResponse response;

	protected @Autowired HttpClientUtil httpClientUtil;

	protected @Autowired JedisUtil jedisUtil;

	/** session管理 */
	protected @Autowired SessionService sessionService;

	protected @Autowired ExcelUtil excelUtil;
 

	/** 获得request session的Id */
	public String getSessionId() {
		return sessionService.getSessionId(request, response);
	}

	protected String getRequestUrl() {
		return request.getRequestURI().substring(1, request.getRequestURI().lastIndexOf("."));
	}
 

	// form表单数据自动填充到对象中
	public void binderData(Object obj) {
		ServletRequestDataBinder binder = new ServletRequestDataBinder(obj);
		// 日期格式进行绑定
		CustomDateEditor dateEditor = new CustomDateEditor(DateTypeEditor.GET_DF_SHORT(), true);
		// 表示如果命令对象有Date类型的属性，将使用该属性编辑器进行类型转换
		binder.registerCustomEditor(Date.class, dateEditor);
		binder.bind(request);
	}
}
